package com.dq.repository.evaluation;

import com.dq.domain.evaluation.EvaluationRecord;
import com.dq.domain.record.ServiceRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @author liuhui
 * @date 2019/11/22 0022 17:25:39
 */
@Repository
public interface EvaluationRecordRepository extends JpaRepository<EvaluationRecord,Long> {

    @Query(nativeQuery = true, value ="SELECT COALESCE(sum(er.average_score),0) FROM `evaluation_record` er LEFT JOIN service_record sr ON er.service_record_id = sr.id where sr.staff_user_id = ?1")
    Long findByScore(Long staffUserId);
    @Query(nativeQuery = true, value ="SELECT COALESCE(count(er.id),0) FROM `evaluation_record` er LEFT JOIN service_record sr ON er.service_record_id = sr.id where sr.staff_user_id = ?1")
    Long findByNum(Long staffUserId);

//    EvaluationRecord findByServiceRecordAndDeletedFalse(ServiceRecord serviceRecord);
    EvaluationRecord findByDeletedFalseAndSubscribeId(Long id);
}
